package zouran.filepractice.service;

import org.junit.Test;

import java.io.*;
import java.util.*;

/**
 * .ini后缀文件读写
 * @author zouran
 * createDate：2023/5/10  22:26
 */
public class IniRead {
    //resources下的相对路径
    public final String relativeUrl="\\study\\1.ini";
    //拼接文件读取路径
    private final String baseUrl=new File(Objects.requireNonNull(this.getClass().getResource("/")).getPath()+relativeUrl).getPath();

    public void writeIni() throws IOException {
        Properties properties=new Properties();
        properties.setProperty("year","2023");
        OutputStream outputStream=new FileOutputStream(baseUrl,true);
        properties.store(outputStream,null);
        outputStream.close();
    }

    public void readIni() throws IOException {
        Properties properties=new Properties();
        InputStream inputStream=new FileInputStream(baseUrl);
        properties.load(inputStream);
        inputStream.close();
        for (Object key:properties.keySet()){
            System.out.println(properties.get(key));
        }
    }
    @Test
    public void ini() throws IOException {
        System.out.println("1.ini文件原有value信息");
        readIni();
        writeIni();
        System.out.println("1.ini文件追加后value信息");
        readIni();
    }
}
